home *** CD-ROM | disk | FTP | other *** search
- Path: svnews.ubinet.ubs.com!ubszh!ubszh!jis
- From: jis@ubszh.net.ch (Johnston Ian (by ubsswop))
- Newsgroups: comp.lang.c++
- Subject: Re: VC++ 4.0 and Templates and the Compiler
- Date: 29 Jan 1996 15:35:10 GMT
- Organization: UBS
- Distribution: world
- Message-ID: <4eipfe$hbm@ubszh.fh.zh.ubs.com>
- References: <310A7C54.4518@eznet.net>
- NNTP-Posting-Host: nol2179.fh.zh.ubs.com
-
- In article <310A7C54.4518@eznet.net>, Joe Mihalich <mihalich@eznet.net> writes:
- |> Hi,
- |>
- |> Anyone who can answer this question will be the hero of
- |> the year. I am using Visual C++ 4.0 on both WIN NT and WIN 95.
- |>
- |> I have defined a class template that is derived from the
- |> MFC class CString. The class template is defined in a DLL.
- |> In order for ALL of the functions to be exported properly,
- |> they have to be instantiated via the compiler.
- |>
- |> Now, not all of the functions are being called from within
- |> the DLL, so the compiler is not instantiating them, which
- |> is not allowing me to call those functions from another
- |> DLL or APP.
-
-
- The only thing I can suggest is to try this:
-
- //MyString.h
-
- template <class TYPE> class CMyString : public CString
- {
- TYPE Left(int nStart);
- { return (TYPE)CString::Left(nStart); }
- TYPE Left(int nStart, int nCount);
- { return (TYPE)CString::Left(nStart, nCount); }
- };
-
- template <class TYPE>
- inline CMyString<TYPE>::Left(int nStart)
- { return (TYPE) CString::Left(nStart); }
-
- template <class TYPE>
- inline CMyString<TYPE>::Left(int nStart, int nCount)
- { return (TYPE) CString::Left(nStart, nCount); }
-
- and compile with -Ob1.
-
- |>
- |> Microsoft provides 3 ways of solving this problem:
- |>
- |> 1) Declare/Define all functions in your class or it's
- |> .h file. All functions defined there are considered
- |> inline and are automatically instantiated. For
- |> example:
- |>
- |> //MyString.h
- |>
- |> template <class TYPE> class CMyString : public CString
- |> {
- |> TYPE Left(int nStart)
- |> { return (TYPE)CString::Left(nStart); }
- |> TYPE Left(int nStart, int nCount)
- |> { return (TYPE)CString::Left(nStart, nCount); }
- |> };
- |>
- |> This is the ideal method for me to use, but it DOES NOT
- |> WORK. All of my functions are defined in the .h files
- |> cuz there not doing anything but calling the base class
- |> functions. The only functions that get instantiated are
- |> the ones that are called from within the DLL. I can verify
- |> this via the .MAP file.
- |>
- |> 2) In the source file where the functions are defined, reference
- |> the function somewhere by taking it's address. I tried this,
- |> but couldn't get it to work either. This method I probably
- |> screwed up, cuz I didn't know how to get the address of a function
- |> when there were multiple overloaded versions of the function.
- |> Any suggestions of how to do this? For example:
- |>
- |> //MyString.h
- |>
- |> template <class TYPE> class CMyString : public CString
- |> {
- |> TYPE Left(int nStart)
- |> { return (TYPE)CString::Left(nStart); }
- |> TYPE Left(int nStart, int nCount)
- |> { return (TYPE)CString::Left(nStart, nCount); }
- |> void Dummy(void);
- |> };
- |>
- |> Now, how do I take the address of either of the LEFT functions?
- |>
- |> //MyString.cpp
- |>
- |> CMyString::Dummy(void)
- |> {
- |> pFunction1 = &this->Left(int nStart);
- |> pFunction2 = &this->Left(int nStart, int nCount);
- |> }
- |>
- |> Is that correct? If it is, than this method did not work
- |> for me either!
-
- No, the syntax would be
-
- &CMyString<TYPE>::Left(int);
- &CMyString<TYPE>::Left(int, int);
-
- |>
- |> 3) Create a dummy function in your base class that calls all
- |> functions. The dummy function does not need to be
- |> called by anyone. For Example:
- |>
- |> CMyString::Dummy(void)
- |> {
- |> this->Left(0);
- |> this->Left(0,0);
- |> }
- |>
- |> Unfortunately this is the only method that worked for me. I consider
- |> this to be an unacceptable solution because it just seems ludicrous
- |> to have to do it this way.
- |>
- |>
- |> If anyone has any ideas on how to make the first solution work, I
- |> would appreciate it. I am assuming that there is some stupid
- |> compiler option that is turning off the expansion of inline
- |> functions or something. (Bye the way, I tried fooling around with
- |> the compiler option in (C/C++ - Optimizations in the build settings
- |> dialog) called "Inline function expansion". The possible options
- |> are: disabled, Inline Functions, Any suitable function. For debug
- |> mode, this option is always set to disabled. I tried setting it
- |> to either of the other two, but it didn't change anything. The help
- |> says that this option is just a suggestion to the compiler anyway.
- |>
- |> Any help will be greatly appreciated.
- |>
- |> Thanks,
- |> Joe Mihalich
- |>
- |> --
- |> Joe Mihalich
- |> Email: mihalich@eznet.net
- |> Voice: 716-482-0089
-